# Copyright 2025 Arm Limited and/or its affiliates.
#
# This source code is licensed under the BSD-style license found in the
# LICENSE file in the root directory of this source tree.
"""Define TOSA profile support lists for INT and FP.

Expose static sets of EXIR operator overloads used by the TOSA partitioner to
seed positive support checks for different profiles.

"""

import operator
from typing import Final, Set

import torch

from executorch.exir.dialects._ops import ops as exir_ops


# INT profile: ops supported via native TOSA ops, decompositions/transformations, precompute, TableOps, etc.
# Note that ops supported via pre-quantization decompositions are not included here.
TOSA_PRO_INT_SupportList: Final[Set] = {
    exir_ops.edge.aten.abs.default,
    exir_ops.edge.aten.add.Tensor,
    exir_ops.edge.aten.any.default,
    exir_ops.edge.aten.any.dim,
    exir_ops.edge.aten.any.dims,
    exir_ops.edge.aten.bitwise_and.Tensor,
    exir_ops.edge.aten.bitwise_or.Tensor,
    exir_ops.edge.aten.bitwise_xor.Tensor,
    exir_ops.edge.aten.bitwise_and.Scalar,
    exir_ops.edge.aten.bitwise_or.Scalar,
    exir_ops.edge.aten.bitwise_xor.Scalar,
    exir_ops.edge.aten.cos.default,
    exir_ops.edge.aten.logical_and.default,
    exir_ops.edge.aten.logical_or.default,
    exir_ops.edge.aten.logical_xor.default,
    exir_ops.edge.aten.logical_not.default,
    exir_ops.edge.aten.arange.start_step,
    exir_ops.edge.aten.expand_copy.default,
    exir_ops.edge.aten.cat.default,
    exir_ops.edge.aten.ceil.default,
    exir_ops.edge.aten.clamp.default,
    exir_ops.edge.aten.cumsum.default,
    exir_ops.edge.aten.bmm.default,
    exir_ops.edge.aten.permute_copy.default,
    exir_ops.edge.aten.hardsigmoid.default,
    exir_ops.edge.aten.hardtanh.default,
    exir_ops.edge.aten.hardswish.default,
    exir_ops.edge.aten.eq.Tensor,
    exir_ops.edge.aten.eq.Scalar,
    exir_ops.edge.aten.erf.default,
    exir_ops.edge.aten.exp.default,
    exir_ops.edge.aten.expm1.default,
    exir_ops.edge.aten.log.default,
    exir_ops.edge.aten.linear.default,
    exir_ops.edge.aten.split_with_sizes_copy.default,
    exir_ops.edge.aten.split_copy.Tensor,
    exir_ops.edge.aten.floor.default,
    exir_ops.edge.aten.full.default,
    exir_ops.edge.aten.full_like.default,
    exir_ops.edge.aten.ge.Tensor,
    exir_ops.edge.aten.ge.Scalar,
    exir_ops.edge.aten.gt.Tensor,
    exir_ops.edge.aten.gt.Scalar,
    exir_ops.edge.aten.le.Tensor,
    exir_ops.edge.aten.le.Scalar,
    exir_ops.edge.aten.lt.Tensor,
    exir_ops.edge.aten.lt.Scalar,
    exir_ops.edge.aten.mul.Tensor,
    exir_ops.edge.aten.neg.default,
    exir_ops.edge.aten.sigmoid.default,
    exir_ops.edge.aten.mean.dim,
    exir_ops.edge.aten.mm.default,
    exir_ops.edge.aten.minimum.default,
    exir_ops.edge.aten.maximum.default,
    exir_ops.edge.aten.repeat.default,
    exir_ops.edge.aten.reciprocal.default,
    exir_ops.edge.aten.relu.default,
    exir_ops.edge.aten.remainder.Tensor,
    exir_ops.edge.aten.rsqrt.default,
    exir_ops.edge.aten.select_copy.int,
    exir_ops.edge.aten.sub.Tensor,
    exir_ops.edge.aten.tanh.default,
    exir_ops.edge.aten.upsample_bilinear2d.vec,
    exir_ops.edge.aten.upsample_nearest2d.vec,
    exir_ops.edge.aten.view_copy.default,
    exir_ops.edge.aten.unsqueeze_copy.default,
    exir_ops.edge.aten.squeeze_copy.dims,
    exir_ops.edge.aten.pow.Tensor_Scalar,
    exir_ops.edge.aten.pow.Tensor_Tensor,
    operator.getitem,
    exir_ops.edge.quantized_decomposed.quantize_per_tensor.default,
    exir_ops.edge.quantized_decomposed.quantize_per_channel.default,
    exir_ops.edge.quantized_decomposed.dequantize_per_tensor.default,
    exir_ops.edge.quantized_decomposed.dequantize_per_channel.default,
    exir_ops.edge.aten.constant_pad_nd.default,
    exir_ops.edge.aten.amax.default,
    exir_ops.edge.aten.amin.default,
    exir_ops.edge.aten.eye.default,
    exir_ops.edge.aten.linspace.default,
    exir_ops.edge.aten.bitwise_left_shift.Tensor,
    exir_ops.edge.aten.__lshift__.Scalar,
    torch.ops.aten.scalar_tensor.default,
    exir_ops.edge.aten.gelu.default,
    exir_ops.edge.aten.alias_copy.default,
    exir_ops.edge.aten.sin.default,
    exir_ops.edge.aten.sinh.default,
    exir_ops.edge.aten.atan.default,
    exir_ops.edge.aten.acosh.default,
    exir_ops.edge.aten._adaptive_avg_pool2d.default,
    exir_ops.edge.aten.sign.default,
    exir_ops.edge.aten.asin.default,
    exir_ops.edge.aten.atanh.default,
    exir_ops.edge.aten.masked_fill.Scalar,
    exir_ops.edge.aten.asinh.default,
    exir_ops.edge.aten.cosh.default,
    exir_ops.edge.aten.acos.default,
    exir_ops.edge.aten.elu.default,
    exir_ops.edge.aten.bitwise_not.default,
    exir_ops.edge.aten.copy.default,
}


# FP profile: ops supported via native TOSA ops, decompositions/transformations, precompute, etc.
TOSA_PRO_FP_SupportList: Final[Set] = {
    exir_ops.edge.aten.abs.default,
    exir_ops.edge.aten.add.Tensor,
    exir_ops.edge.aten.any.default,
    exir_ops.edge.aten.any.dim,
    exir_ops.edge.aten.any.dims,
    exir_ops.edge.aten.logical_and.default,
    exir_ops.edge.aten.logical_or.default,
    exir_ops.edge.aten.logical_xor.default,
    exir_ops.edge.aten.logical_not.default,
    exir_ops.edge.aten.arange.start_step,
    exir_ops.edge.aten.expand_copy.default,
    exir_ops.edge.aten.cat.default,
    exir_ops.edge.aten.ceil.default,
    exir_ops.edge.aten.clamp.default,
    exir_ops.edge.aten.cos.default,
    exir_ops.edge.aten.cumsum.default,
    exir_ops.edge.aten.bmm.default,
    exir_ops.edge.aten.permute_copy.default,
    exir_ops.edge.aten.hardsigmoid.default,
    exir_ops.edge.aten.hardtanh.default,
    exir_ops.edge.aten.hardswish.default,
    exir_ops.edge.aten.div.Tensor,
    exir_ops.edge.aten.div.Tensor_mode,
    exir_ops.edge.aten.eq.Tensor,
    exir_ops.edge.aten.eq.Scalar,
    exir_ops.edge.aten.erf.default,
    exir_ops.edge.aten.exp.default,
    exir_ops.edge.aten.expm1.default,
    exir_ops.edge.aten.log.default,
    exir_ops.edge.aten.linear.default,
    exir_ops.edge.aten.split_with_sizes_copy.default,
    exir_ops.edge.aten.split_copy.Tensor,
    exir_ops.edge.aten.floor.default,
    exir_ops.edge.aten.full.default,
    exir_ops.edge.aten.full_like.default,
    exir_ops.edge.aten.ge.Tensor,
    exir_ops.edge.aten.ge.Scalar,
    exir_ops.edge.aten.gt.Tensor,
    exir_ops.edge.aten.gt.Scalar,
    exir_ops.edge.aten.le.Tensor,
    exir_ops.edge.aten.le.Scalar,
    exir_ops.edge.aten.lt.Tensor,
    exir_ops.edge.aten.lt.Scalar,
    exir_ops.edge.aten.mul.Tensor,
    exir_ops.edge.aten.ne.Tensor,
    exir_ops.edge.aten.ne.Scalar,
    exir_ops.edge.aten.neg.default,
    exir_ops.edge.aten.add.Scalar,
    exir_ops.edge.aten.sub.Scalar,
    exir_ops.edge.aten.mul.Scalar,
    exir_ops.edge.aten.div.Scalar,
    exir_ops.edge.aten._native_batch_norm_legit_no_training.default,
    exir_ops.edge.aten.native_layer_norm.default,
    exir_ops.edge.aten.native_group_norm.default,
    exir_ops.edge.aten.sigmoid.default,
    exir_ops.edge.aten.mean.dim,
    exir_ops.edge.aten.mean.default,
    exir_ops.edge.aten.mm.default,
    exir_ops.edge.aten.minimum.default,
    exir_ops.edge.aten.maximum.default,
    exir_ops.edge.aten.repeat.default,
    exir_ops.edge.aten.reciprocal.default,
    exir_ops.edge.aten.relu.default,
    exir_ops.edge.aten.remainder.Scalar,
    exir_ops.edge.aten.remainder.Tensor,
    exir_ops.edge.aten.leaky_relu.default,
    exir_ops.edge.aten.sqrt.default,
    exir_ops.edge.aten.rsqrt.default,
    exir_ops.edge.aten.round.default,
    exir_ops.edge.aten._softmax.default,
    exir_ops.edge.aten.select_copy.int,
    exir_ops.edge.aten._log_softmax.default,
    exir_ops.edge.aten.sub.Tensor,
    exir_ops.edge.aten.tanh.default,
    exir_ops.edge.aten.upsample_bilinear2d.vec,
    exir_ops.edge.aten.upsample_nearest2d.vec,
    exir_ops.edge.aten.var.correction,
    exir_ops.edge.aten.var.dim,
    exir_ops.edge.aten.view_copy.default,
    exir_ops.edge.aten.unsqueeze_copy.default,
    exir_ops.edge.aten.squeeze_copy.dims,
    exir_ops.edge.aten.pow.Tensor_Scalar,
    exir_ops.edge.aten.pow.Tensor_Tensor,
    operator.getitem,
    exir_ops.edge.aten.constant_pad_nd.default,
    exir_ops.edge.aten.amax.default,
    exir_ops.edge.aten.amin.default,
    exir_ops.edge.aten.eye.default,
    exir_ops.edge.aten.linspace.default,
    exir_ops.edge.aten.bitwise_left_shift.Tensor,
    exir_ops.edge.aten.__lshift__.Scalar,
    torch.ops.aten.scalar_tensor.default,
    exir_ops.edge.aten.gelu.default,
    exir_ops.edge.aten.alias_copy.default,
    exir_ops.edge.aten.sin.default,
    exir_ops.edge.aten.sinh.default,
    exir_ops.edge.aten.atan.default,
    exir_ops.edge.aten.acosh.default,
    exir_ops.edge.aten._adaptive_avg_pool2d.default,
    exir_ops.edge.aten.sign.default,
    exir_ops.edge.aten.asin.default,
    exir_ops.edge.aten.atanh.default,
    exir_ops.edge.aten.addmm.default,
    exir_ops.edge.aten.masked_fill.Scalar,
    exir_ops.edge.aten.asinh.default,
    exir_ops.edge.aten.cosh.default,
    exir_ops.edge.aten.glu.default,
    exir_ops.edge.aten.logit.default,
    exir_ops.edge.aten.acos.default,
    exir_ops.edge.aten.elu.default,
    exir_ops.edge.aten.copy.default,
    exir_ops.edge.aten.floor_divide.default,
}


__all__ = [
    "TOSA_PRO_INT_SupportList",
    "TOSA_PRO_FP_SupportList",
]
